*AUTHOR: Jonathan Davis
*DATE: 20 May 2025
*PURPOSE: Program to organize code for "Labor Market Design Can Improve Match Outcomes: Evidence from Matching Teach For America Teachers to Schools"



* Set global macro for main project directory
global dir "" 
cd ${dir}


clear all
set more off


* Set seeds for reproducibility
set seed 34887172
set sortseed 187392842





* Install added packages 

* Set local to 1 to install packages
local install_packages 1

if `install_packages'==1 {
cap ssc install jarowinkler
cap ssc install reclink
cap ssc install synth
cap ssc install unique

}






* Sets global macros for project subdirectories that are referenced throughout code
global raw "${dir}/Raw/"
global data "${dir}/Data/"
global programs "${dir}/Programs/"
global results "${dir}/Results/"

* Set other global macros
global bootstraps 500






* Global macro with control variables
global X  " lnc gpa undergrad_satmt75 undergrad_sat_ms  major_soc major_mathScience major_humanities doubleMajor yearsSinceCollege_1_2 yearsSinceCollege_3_5 yearsSinceCollege_6p female black hispanic otherRace"





* ---------------------*
*  Main Paper Analysis *
* ---------------------* 


do ${programs}1_teacherpreferences.do /* Estimates teacher preferences. Produces teacher estimates in Table 1 and Table A4. Also saves teacher utility draws for simulation. */

do ${programs}2_schoolpreferences.do  /* Estimates school preferences. Produces teacher estimates in Table 1. Also saves school position utility draws for simulation. */

do ${programs}3_prepSimulation.do /* Prep simulation data */


do ${programs}4_estimateFOthresholds.do /* Estimate thresholds for FO */

do ${programs}5_simulateFO.do /* Simulate FO */

do ${programs}6_simulateOtherMechanisms.do /* Simulate DA, TP-DA, CP-DA, RSD, and Snake Draft */

do ${programs}7_cleanSimulation.do /* Compile simulation results into one file */


do ${programs}8_anSimulation.do /* Saves estimates based on simulation, including Panel A of Table 2, Table 3, and Table 4 */



do ${programs}9_hiringDiffInDiff.do /* Diff-in-diff interview day outcomes. Produces Panel B of Table 2 */

do ${programs}10_retention_did.do /* Diff-in-diff retention impacts. Panel A of Table 5 */

do ${programs}11_retention_synth.do /* Synthetic control retention estimates. Panel B of Table 5 */

do ${programs}12_satisfaction_did.do /* Diff-in-diff satisfaction impacts. Panel A of Table 6 */

do ${programs}13_satisfaction_synth.do /* Synthetic control satisfaction estimates. Panel B of Table 6 */



* ------------*
*  Appendices *
* ------------*



do ${programs}14_intDayAttend.do /* Creates appendix Tables A1, A2, and A5 */

do ${programs}15_schedules.do /* Create appendix Tables A3 and A10 */

do ${programs}16_attritionCorrelates.do /* Creates appendix Table A6 */ 

do ${programs}17_retentionHumanities.do /* Creates appendix Table A7 */ 

do ${programs}18_satisfactionHumanities.do /* Creates appendix Table A8 */ 


do ${programs}19_performance_did.do /* Creates appendix Table A9 and Figure A2 */

do ${programs}20_fo_thresholds.do /* Creates Appendix Figure A1 */


* --------------------------------------- *
* Delete intermediate files to save space *
* --------------------------------------- *

local cleanup 0

if `cleanup'==1 {
	
	 * Clean up all of the intermediate files
 	forv bs=0/$bootstraps {
		forv d=1/3 {
			cap rm ${data}Simulation/sim_data_d`d'_bs`bs'.dta
			forv o=1/10 {
				cap rm ${data}Simulation/sim_multi_d`d'_o`o'_bs`bs'.dta 
				cap rm ${data}Simulation/optimal_taus`d'_o`o'_bs`bs'.dta
				cap rm ${data}Simulation/sim_fo_d`d'_o`o'_bs`bs'.dta
				cap rm ${data}Siulation/sim_res_d`d'_o`o'_bs`bs'.dta
			}
		}
	}
	rm ${data}Simulation/sim_data.dta
	rm ${data}Simulation/teacher_uhats.dta
	rm ${data}Simulation/school_uhats.dta
}




